package com.spzx.product.api.factory;

import com.spzx.common.core.constant.ServiceNameConstants;
import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteCategoryService;
import com.spzx.product.api.domain.vo.CategoryVo;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * OpenFeign提供降级处理
 */
//@Slf4j
//@Component
public class RemoteCategoryFallbackFactory implements FallbackFactory<RemoteCategoryService> {

    Logger log = LoggerFactory.getLogger(RemoteCategoryFallbackFactory.class);

    @Override
    public RemoteCategoryService create(Throwable cause) {
        log.error("远程调用【"+ ServiceNameConstants.PRODUCT_SERVICE +"】服务降级处理：");
        return new RemoteCategoryService() {
            @Override
            public R<List<CategoryVo>> getCategoryOne(String source) {
                log.error("远程调用getCategoryOne接口降级处理");
                //return R.fail(new ArrayList<>()); //兜底数据结果
                return R.fail("分类接口调用降级处理");
            }

            @Override
            public R<List<CategoryVo>> tree(String source) {
                log.error("远程调用获取三级分类接口降级处理");
                //return R.fail(new ArrayList<>()); //兜底数据结果
                return R.fail("获取三级分类接口调用降级处理");
            }
        };
    }
}
